package com.gitee.wsl.net.client.currency

import com.gitee.wsl.net.client.BaseNetworkService
import com.gitee.wsl.service.currency.model.Conversion
import com.gitee.wsl.service.currency.toConversionModel
import kotlinx.coroutines.CoroutineDispatcher
import timber.log.Timber

interface BackendApiService {
    suspend fun getConversion(base: String): Conversion
}

class BackendApiServiceImpl(
    private val backendApi: BackendApi,
    ioDispatcher: CoroutineDispatcher
) : BackendApiService, BaseNetworkService(ioDispatcher) {
    override suspend fun getConversion(
        base: String
    ) = apiRequest {
        Timber.v ( "BackendApiServiceImpl getConversion $base" )

        backendApi.getExchangeRate(withEmptyParameterCheck(base))
            .toConversionModel()
    }
}